/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package percussiongenerator.commands;

import org.jfonia.connect5.intervals.Interval;
import org.jfonia.connect5.intervals.LinkedDoubleIntervalList;
import org.jfonia.connect5.intervals.LinkedIntIntervalList;
import org.jfonia.connect5.intervals.LinkedLongIntervalList;
import org.jfonia.model.PerformanceNode;
import org.jfonia.model.PerformanceSequence;
import org.jfonia.model.elements.Tone;

/**
 *
 * @author jannes
 */
public class SplitTone implements ICommand{
    PerformanceNode perNode;
    PerformanceSequence perSeq;    

    public SplitTone(PerformanceNode perNode, PerformanceSequence perSeq){
        this.perNode = perNode;
        this.perSeq = perSeq;
    }

    public void execute() {
        int index;
        index = perSeq.indexOf(perNode);
        PerformanceNode newNode = perNode.clone();
        newNode.setDifference(perNode.getDifference()-perNode.getDifference()/2);
        perNode.setDifference(perNode.getDifference()/2);
        perSeq.insert(index+1, newNode);
    }

    public void undo() {
        int index;
        index = perSeq.indexOf(perNode);
        perNode.setDifference(perNode.getDifference() + perSeq.getIntervalFromIndex(index+1).getDifference());
        perSeq.remove(index+1);
    }
}
